//
//  LYNetworkTool.swift
//  Sina_Weibo2
//
//  Created by Elsevier on 16/5/13.
//  Copyright © 2016年 Yang Lu. All rights reserved.
//

import UIKit
import AFNetworking

enum RequestMethod: String{
    case GET = "get"
    case POST = "post"
}

class LYNetworkTool: NSObject {
    
    static let sharedInstance: LYNetworkTool = LYNetworkTool()
    
    private let afnManager : AFHTTPSessionManager = {
        let afn = AFHTTPSessionManager(baseURL: NSURL(string :"https://api.weibo.com/"))
        afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        return afn
    }()
    
    func  request(method: RequestMethod, URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?){
        
        if method == RequestMethod.GET {
            afnManager.GET(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        } else {
            afnManager.POST(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
    }
}
